package ai.ann.image.trainer.gui;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;

import ai.ann.Property;

import util.essential.VariableValueGetter;

/*
 * Estudiante de Ingenier�a de Ejecuci�n en Computaci�n e Inform�tica.
 * UBB - FACE - DAI - IECI.
 * Chill�n - B�o-B�o - Chile.
 * Creado el 21-01-2005
 */

/**
 * @author Sebasti�n Alexis Moraga Garrido.
 */
public class ColorMatrixComponent extends Panel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//Constants:
	private static final VariableValueGetter variableValueGetter = new VariableValueGetter(Property.CONFIGURATION_FILE_NAME);
	public static final int HEIGHT_SIZE = Integer.parseInt(ColorMatrixComponent.variableValueGetter.getStringValue("taste_size"));
	public static final int WIDTH_SIZE = Integer.parseInt(ColorMatrixComponent.variableValueGetter.getStringValue("taste_size"));
	private final Color[][]DEFAULT_COLOR_MATRIX={	{Color.WHITE,Color.WHITE,Color.WHITE,Color.WHITE,Color.WHITE},
													{Color.WHITE,Color.WHITE,Color.WHITE,Color.WHITE,Color.WHITE},
													{Color.WHITE,Color.WHITE,Color.WHITE,Color.WHITE,Color.WHITE},
													{Color.WHITE,Color.WHITE,Color.WHITE,Color.WHITE,Color.WHITE},
													{Color.WHITE,Color.WHITE,Color.WHITE,Color.WHITE,Color.WHITE}};
	private Label[][]label;
	//private LinkedList shapeList;

	// Constructor:
	public ColorMatrixComponent(int width, int height) {
		this.setPreferredSize(new Dimension(width*ColorMatrixComponent.WIDTH_SIZE, height*ColorMatrixComponent.HEIGHT_SIZE));
		this.setLayout(new GridLayout(ColorMatrixComponent.HEIGHT_SIZE,ColorMatrixComponent.WIDTH_SIZE));
		this.label = new Label[ColorMatrixComponent.HEIGHT_SIZE][ColorMatrixComponent.WIDTH_SIZE];
		for (int i = 0; i < this.label.length; i++) {
			for (int j = 0; j < this.label[i].length; j++) {
				this.label[i][j] = new Label();
				this.label[i][j].setPreferredSize(new Dimension(ColorMatrixComponent.WIDTH_SIZE, ColorMatrixComponent.HEIGHT_SIZE));
				this.add(this.label[i][j]);
			}			
		}
		//this.shapeList = new LinkedList();
		this.setColorMatrix(this.DEFAULT_COLOR_MATRIX);
	}

	// Métodos:
	public void setColorMatrix(Color[][]matrix) {
		//this.updateMatrix(matrix);
		//this.shapeList.clear();
		//Rectangle2D r;ShapeBean s;
		if(matrix.length>0&&matrix.length==this.label.length&&matrix[0].length==this.label[0].length){
			for (int y = 0; y < matrix.length; y++) {
				for (int x = 0; x < matrix[y].length; x++) {
					/*r = new Rectangle2D.Float(x,y,this.WIDTH_SIZE,this.HEIGHT_SIZE);
					s = new ShapeBean(r,matrix[y][x]);
					this.shapeList.add(s);*/
					this.label[y][x].setBackground(matrix[y][x]);
				}
			}
		}
		this.repaint();
		//this.updateMatrix(matrix);
	}

	/*private void updateMatrix(Color[][] matrix) {
		//if(matrix.length>0&&matrix.length==this.label.length&&matrix[0].length==this.label[0].length){
			this.removeAll();
			this.setLayout(new GridLayout(this.HEIGHT_SIZE,this.WIDTH_SIZE));
			this.label = new Label[this.HEIGHT_SIZE][this.WIDTH_SIZE];
			for (int i = 0; i < this.label.length; i++) {
				for (int j = 0; j < this.label[i].length; j++) {
					this.label[i][j] = new Label();
					this.label[i][j].setPreferredSize(new Dimension(this.WIDTH_SIZE, this.HEIGHT_SIZE));
					this.label[i][j].setBackground(matrix[i][j]);
					this.add(this.label[i][j]);
				}			
			}
			this.repaint();
			this.setVisible(true);
		//}
	}
	/*public void paint(Graphics g) {
		Graphics2D g2D = (Graphics2D) g;
		this.setBackground(Color.BLACK);
		if(this.shapeList != null){
			ShapeBean tmp;
			for(Iterator i=this.shapeList.iterator();i.hasNext();){
				tmp = ((ShapeBean)i.next());
				g2D.setColor(tmp.getRepresentativeColor());
				g2D.fill(tmp.getShape());
			}
		}
	}*/
}
